package com.example.cinema;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Constraints;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.example.cinema.adapter.RecyclerAdapter;
import com.example.cinema.adapter.ShortCommentAdapter;
import com.example.cinema.bindingdata.CommentShortData;
import com.example.cinema.bindingdata.ShortBindingData;
import com.example.cinema.database.DataBaseMethod;
import com.example.cinema.databinding.FragmentBlank1BindingImpl;
import com.example.cinema.drawview.BufferProgress;
import com.example.cinema.drawview.ShortPlayerVideo;
import com.example.cinema.request.RequestData;
import com.example.cinema.request.RequestSend;
import com.example.cinema.testdara.TestData;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Currency;
import java.util.List;


import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link BlankFragment1#newInstance} factory method to
 * create an instance of this fragment.
 */
public class BlankFragment1 extends Fragment {

    @Override
    public void onPause() {
        Log.i("PPPP", "失焦");
        if (CurrentPlay != null) {
            CurrentPlay.Playstop();
            if (DialogPlayer != null) {
                DialogPlayer.Playstop();
            }
            Log.i("PPPP", "停止");
        }
        super.onPause();
    }

    @Override
    public void onResume() {
        Log.i("PPPP", "显示");
        if (CurrentPlay != null && isdialogplayer == false) {
            CurrentPlay.Playstart();
        } else if (isdialogplayer) {
            DialogPlayer.Playstart();
        }
        FBB.video.setChecked(true);
        super.onResume();
    }

    @Override
    public void onDestroy() {
        Log.i("PPPP", "结束");
        if (CurrentPlay != null) {
            CurrentPlay.Playstop();
            CurrentPlay.Playrelease();
            DialogPlayer.Playstop();
            DialogPlayer.Playrelease();
        }
        super.onDestroy();
    }

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    public BlankFragment1() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment BlankFragment1.
     */
    // TODO: Rename and change types and number of parameters
    public static BlankFragment1 newInstance(String param1, String param2) {
        BlankFragment1 fragment = new BlankFragment1();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }

    }


    private static FragmentBlank1BindingImpl FBB;
    private static boolean isinit = false;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (!isinit) {
            FBB = DataBindingUtil.inflate(inflater, R.layout.fragment_blank1, container, false);
        }
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) {
            View view = container.getRootView();
            view.setSystemUiVisibility(View.GONE);
        } else if (Build.VERSION.SDK_INT >= 19) {
            View view = container.getRootView();
            int UIOP = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
            view.setSystemUiVisibility(UIOP);
        }

        return FBB.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (!isinit) {
            init();
            setAdapter();
            initlintener();
            isinit = true;
        }
    }

    private UserAttribute attribute;

    private void init() {
        attribute = (UserAttribute) getActivity().getApplication();
        FBB.recycler.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));//设置纵向
        FBB.recycler.setItemAnimator(new DefaultItemAnimator());//设置默认动画
        new PagerSnapHelper().attachToRecyclerView(FBB.recycler);

        InitDialog();

    }

    //弹出完整播放
    private AlertDialog alertDialog;
    private ShortPlayerVideo DialogPlayer;
    private boolean isdialogplayer = false;

    private void InitDialog() {
        if (CurrentPlay != null) {
            CurrentPlay.Playstop();
        }
        int h = getResources().getDisplayMetrics().heightPixels;
        int w = getResources().getDisplayMetrics().widthPixels;
        DialogPlayer = new ShortPlayerVideo(getContext());
        LinearLayout.LayoutParams layoutParamss = new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT);
        layoutParamss.width = w;
        layoutParamss.height = h;
        layoutParamss.gravity = Gravity.CENTER;
        DialogPlayer.setLayoutParams(layoutParamss);

        //重叠容器
        FrameLayout frameLayout = new FrameLayout(getContext());
        frameLayout.addView(DialogPlayer);


        //返回
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(60, 60);
        layoutParams.topMargin = 20;
        layoutParams.leftMargin = 20;
        ImageView close = new ImageView(getContext());
        close.setLayoutParams(layoutParams);
        close.setImageResource(R.mipmap.fanhui);
        frameLayout.addView(close);

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT);
        params.gravity = Gravity.CENTER;
        params.width = w;
        params.height = h;
        frameLayout.setLayoutParams(params);


        DialogPlayer.setBackgroundColor(Color.BLACK);
        alertDialog = new AlertDialog.Builder(getContext())
                .setView(frameLayout)
                .create();
        Window window = alertDialog.getWindow();
        window.getDecorView().setBackgroundColor(Color.RED);
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams wparam = window.getAttributes();
        wparam.width = w;
        wparam.height = h;
        wparam.gravity = Gravity.CENTER;
        window.setAttributes(wparam);
        alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                isdialogplayer = false;
                DialogPlayer.Playstop();
                DialogPlayer.Playrelease();
            }
        });
        alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {

                if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) {
                    View view = FBB.recycler.getRootView();
                    view.setSystemUiVisibility(View.GONE);
                } else if (Build.VERSION.SDK_INT >= 19) {
                    View view = FBB.recycler.getRootView();
                    int UIOP = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
                    view.setSystemUiVisibility(UIOP);
                }
            }
        });
        //关闭
        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.cancel();
            }
        });
    }

    //适配器
    private RecyclerAdapter adapter;
    private List<ShortBindingData> data = new ArrayList<>();
    private boolean abbs = true;

    private void setAdapter() {
        DataBaseMethod dataBaseMethod = new DataBaseMethod(getContext(), "videom3u8");
        data = dataBaseMethod.GetShortData();
        if (data.size() > 0) {
            currentdata = data.get(0);
            Log.i("UUUU", data.size() + "数量");
            Log.i("UUUU", data.get(0).videourl.get());
//            Log.i("UUUU",data.get(0).centimg.get());
            Log.i("UUUU", data.get(0).image.get());
            Log.i("UUUU", data.get(0).imgurl.get());
            videoid = data.get(0).videoid.get();
        }
        adapter = new RecyclerAdapter(data, R.layout.short_video_item, getContext());
        FBB.recycler.setAdapter(adapter);

        if (abbs && data.size() > 0) {
            Log.i("QQDSD", "开始获取");
            abbs = false;
            userid = data.get(0).useruid.get();
            if (attribute.getUID() != null) {
                IsFollow();
            }
        }
        Log.i("QQDSD", "开始获取1" + userid);
    }

    //初始化监听
    private static ShortPlayerVideo CurrentPlay;
    private ShortPlayerVideo PrevPlay;
    private String typeid = "1024";
    private int page = 1;
    private int limit = 15;
    private String videoid;
    private ShortBindingData currentdata;
    private View followView;
    private View Cview;
    private String userid;

    private boolean switchs = true;

    private void initlintener() {
        //跳到搜索
        FBB.search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction("search");
                startActivity(intent);
            }
        });
        //滚动监听
        FBB.recycler.addOnScrollListener(new RecyclerView.OnScrollListener() {

            private int Prev;

            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();//减Relcycler的布局转换为线性管理器
                int t = manager.findLastVisibleItemPosition();
                int len = manager.getItemCount();//获取子View总数
                if (newState == RecyclerView.SCROLL_STATE_DRAGGING)//判断状态正在拖动的
                {
                    Prev = manager.findLastCompletelyVisibleItemPosition();//获取正在拖到的Item索引
                    View Pview = manager.findViewByPosition(Prev);//根据索引获取ItemView
                    Log.i("KKK", Prev + "");
                    if (Pview == null) {//判断是否空
                        return;
                    }
                    PrevPlay = Pview.findViewById(R.id.player);//获取Item中的视频播放View
                    if (t >= len - 2) {
                        page++;
                        //获取数据
                        GetShortVideo();
                    }
                }
                if (newState == RecyclerView.SCROLL_STATE_IDLE)//判断状态拖动停止
                {
                    cmmentdata.clear();//清空评价数据
                    int y = Math.abs(scrolly);//负数转数值
                    int current = manager.findLastCompletelyVisibleItemPosition();//获取当前完全可见的Item索引
                    if (current < 0)//判断如果小于0 则不做任何处理 比如没有滑动完成 获取的索引会是-1
                    {
                        return;
                    }

                    videoid = data.get(current).videoid.get();
                    Log.i("HHHH", data.get(current).title.get());
                    currentdata = data.get(current);
                    Cview = manager.findViewByPosition(current);//获取当前可见ItemView对象
                    BufferProgress progress = Cview.findViewById(R.id.progress);
                    progress.Animators();
                    CurrentPlay = Cview.findViewById(R.id.player);//获取Item中的播放器View
                    int height = CurrentPlay.getHeight();//获取高度用来跟 滚动的Y坐标进行对别判断是否完成了滚动
                    if (y > (height - 100)) {
                        PrevPlay.Playstop();//停止上一个播放器
                        PrevPlay.Playrelease();//释放上一个播放器
                        Log.i("PPP", "滚动成功");
                        CurrentPlay.loadVideo();//开始当前ItemView播放器播放
                        if (attribute.getUID() != null) {
                            IsFollow();
                        }
                        userid = data.get(current).useruid.get();
                    }
                    scrolly = 0;//将计数Y坐标清空为0
                }

            }

            private int scrolly = 0;

            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                Log.i("YYY", scrolly + "");
                scrolly += dy;//计数滑动的Y值
            }
        });
        //评论点击
        adapter.setCommentclick(new RecyclerAdapter.onCommentClickListener() {
            @Override
            public void CommentClick() {
                if (cmmentdata.size() < 1) {
                    GetComment();
                }
                commentdata();
            }
        });
        //分享点击
        adapter.setShareClick(new RecyclerAdapter.onShareClickListener() {
            @Override
            public void ShareClick() {
                sharedata();
            }
        });
        //VIP观看完整
        adapter.setVipClick(new RecyclerAdapter.onVipVideoClickListener() {
            @Override
            public void VipClick() {
                if (!switchs) {
                    return;
                }
                switchs = false;

                if (CurrentPlay != null) {
                    CurrentPlay.Playstop();
                }
                new Thread() {
                    @Override
                    public void run() {
                        if (attribute.getUID() == null) {
                            handler.sendEmptyMessage(1004);
                            return;
                        }
                        RequestSend send = new RequestSend(getContext());
                        boolean b;
                        if (attribute.getAppMode() == 0) {
                            b = true;
                        } else {
                            b = send.VipCheck(attribute.getUID());
                        }
                        Log.i("JJJDD",b+"");
                        if (b) {
                            if (currentdata == null) {
                                return;
                            }
                            GetVurl();
                            Log.i("JJJDD",b+"提取URL");
                        } else {
                            handler.sendEmptyMessage(1003);
                        }
                        switchs = true;
                    }
                }.start();
            }
        });
        //头像点击
        adapter.setUserClick(new RecyclerAdapter.onUserImgClickListener() {
            @Override
            public void UserImgClick() {
                //头像点击
                if (attribute.getUID() != null) {
                    LinearLayoutManager manager = (LinearLayoutManager) FBB.recycler.getLayoutManager();//减Relcycler的布局转换为线性管理器
                    int t = manager.findLastVisibleItemPosition();
                    Log.i("QQQQ", t + "");
                    ShortBindingData svideo = data.get(t);
                    String s = svideo.useruid.get();
                    Intent intent = new Intent();
                    intent.setAction("uservideoliat");
                    intent.putExtra("uid", s);
                    startActivity(intent);
                } else {
                    Intent intent = new Intent();
                    intent.setAction("sign");
                    startActivity(intent);
                }
            }
        });
        //分类点击
        FBB.rgroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.typebtn) {
                    Intent intent = new Intent();
                    intent.setAction("movietype");
                    startActivity(intent);
                }
            }
        });
        //关注
        adapter.setFollowClick(new RecyclerAdapter.onFollowClickListener() {
            @Override
            public void FollowClick(View view, Object obj) {
                Log.i("QQQQQQQQ", "关注");
                followView = view;
                if (attribute.getUID() == null || attribute.getToken() == null) {
                    Intent intent = new Intent();
                    intent.setAction("sign");
                    startActivity(intent);
                    return;
                }
                new Thread() {
                    @Override
                    public void run() {
                        ShortBindingData data = (ShortBindingData) obj;
                        RequestSend requestSend = new RequestSend(getContext());

                        boolean b = requestSend.Follow(attribute.getUID(), data.useruid.get(), attribute);
                        Log.i("QQQQQQQQ", "关注结果" + b);
                        Message message = new Message();
                        message.what = 1007;
                        message.obj = b;
                        handler.sendMessage(message);
                    }
                }.start();

            }
        });


    }

    //获取评论数据
    private int cp = 1;
    private int cl = 30;
    private List<CommentShortData> cmmentdata = new ArrayList<>();

    private void GetComment() {
        new Thread() {
            @Override
            public void run() {
                RequestData requestData = new RequestData(getContext());
                List<CommentShortData> data = requestData.GetShortComment(videoid, cp, cl);
                cmmentdata.addAll(data);
                handler.sendEmptyMessage(1002);
            }
        }.start();
    }

    //弹出评论区
    private AlertDialog dialog;
    private ShortCommentAdapter scadapter;
    private EditText editText;

    private void commentdata() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.comment_dialog, null);
        dialog = new AlertDialog.Builder(getContext())
                .setView(view)
                .create();
        ListView listView = view.findViewById(R.id.commentlist);
        scadapter = new ShortCommentAdapter(getContext(), cmmentdata, R.layout.comment_item);
        listView.setAdapter(scadapter);
        dialog.show();
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {

                if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) {
                    View view = FBB.recycler;
                    view.setSystemUiVisibility(View.GONE);
                } else if (Build.VERSION.SDK_INT >= 19) {
                    View view = FBB.recycler;
                    int UIOP = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
                    view.setSystemUiVisibility(UIOP);
                }
            }
        });
        int width = getResources().getDisplayMetrics().widthPixels;
        Window window = dialog.getWindow();
        window.setGravity(Gravity.BOTTOM);
        window.getDecorView().setMinimumWidth(width);
        window.getDecorView().setPadding(0, 0, 0, 0);
        window.getDecorView().setBackgroundResource(R.drawable.dialog_round_bag);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = width;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setWindowAnimations(R.style.dialoganim);
        window.setAttributes(params);
        //评论点赞
        scadapter.SetZanListener(new ShortCommentAdapter.OnZanListener() {
            @Override
            public void ZanClick(ImageView view, int positon, Object data) {
                view.getDrawable().setLevel(2);
                RequestSend requestSend = new RequestSend(getContext());
                CommentShortData shortData = (CommentShortData) data;
                new Thread() {
                    @Override
                    public void run() {
                        boolean b = requestSend.SendUserZan(videoid, shortData.usersid.get());
                        if (b) {
                            int z = Integer.valueOf(shortData.zannumbe.get());
                            shortData.zannumbe.set(String.valueOf(z + 1));
                        }
                    }
                }.start();
            }
        });
        //提交评论
        editText = view.findViewById(R.id.text);
        ImageView sendimg = view.findViewById(R.id.sendbtn);
        //提交评论
        sendimg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (attribute.getToken() == null || attribute.getUID() == null) {
                    Intent intent = new Intent();
                    intent.setAction("sign");
                    startActivity(intent);
                    return;
                }
                String text = editText.getText().toString();
                if (text.isEmpty()) {
                    Toast.makeText(getContext(), "内容不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }
                String ss = text.replace(" ", "");
                if (ss.length() < 1) {
                    Toast.makeText(getContext(), "内容不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }
                new Thread() {
                    @Override
                    public void run() {
                        RequestSend send = new RequestSend(getContext());
                        boolean b = send.SendAssess(currentdata.videoid.get(), attribute.getUID(), text);
                        Message message = new Message();
                        message.what = 1006;
                        message.obj = b;
                        handler.sendMessage(message);
                    }
                }.start();
            }
        });
    }

    //弹出分享区
    private AlertDialog shareDialog;

    private void sharedata() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.share_dialog, null);
        shareDialog = new AlertDialog.Builder(getContext())
                .setView(view).create();
        LinearLayout wx = view.findViewById(R.id.wxclick);
        LinearLayout qq = view.findViewById(R.id.qqclick);

        shareDialog.show();
        shareDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {

                if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) {
                    View view = getView();
                    view.setSystemUiVisibility(View.GONE);
                } else if (Build.VERSION.SDK_INT >= 19) {
                    View view = getView();
                    int UIOP = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
                    view.setSystemUiVisibility(UIOP);
                }
            }
        });
        int width = getResources().getDisplayMetrics().widthPixels;
        Window window = shareDialog.getWindow();
        window.setGravity(Gravity.BOTTOM);
        window.getDecorView().setMinimumWidth(width);
        window.getDecorView().setPadding(0, 0, 0, 0);
        window.getDecorView().setBackgroundResource(R.drawable.dialog_round_bag);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = width;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setWindowAnimations(R.style.dialoganim);
        window.setAttributes(params);


        //微信分享点击
        wx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        //QQ分享点击
        qq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

    //取数据
    private void GetShortVideo() {
        new Thread() {
            @Override
            public void run() {
                Log.i("JJJ", "开始获取数据");
                RequestData requestData = new RequestData(getContext());
                List<ShortBindingData> sbd = requestData.GetShortVideo(typeid, page, limit);
                Log.i("TTT", sbd.size() + "数量");
                Log.i("TTT", page + "页码");
                Log.i("TTT", limit + "数量");
                data.addAll(sbd);

                handler.sendEmptyMessage(1000);
            }
        }.start();
    }

    //提取播放链接
    private void GetVurl() {
        new Thread() {
            @Override
            public void run() {

                if(attribute.getAppMode()==0)
                {
                    Message message = new Message();
                    message.what = 1005;
                    message.obj = currentdata.videourl.get();
                    handler.sendMessage(message);
                    return;
                }

                RequestData requestData = new RequestData(getContext());
                String url = requestData.GetVipUrl(currentdata.videoid.get(), attribute);
                Log.i("HHH", "获取到播放" + url);
                if (url != null) {
                    Message message = new Message();
                    message.what = 1005;
                    message.obj = url;
                    handler.sendMessage(message);
                }

            }
        }.start();
    }

    //判断是否已关注
    private void IsFollow() {
        new Thread() {
            @Override
            public void run() {
                RequestSend requestSend = new RequestSend(getContext());
                Log.i("JJDDJ", attribute.getUID() + ":ID");
                Log.i("JJDDJ", userid + ":ID");
                boolean abool = requestSend.isFollow(attribute.getUID(), userid, attribute);
                Log.i("JJDDJ", abool + "结果");
                Message message = new Message();
                message.what = 1008;
                message.obj = abool;
                handler.sendMessage(message);
            }
        }.start();
    }


    Handler handler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(@NonNull Message msg) {
            if (msg.what == 1000) {
                adapter.notifyDataSetChanged();

            }
            if (msg.what == 1002) {
                scadapter.notifyDataSetChanged();
            }
            if (msg.what == 1003) {
                Toast.makeText(getContext(), "您还不是VIP哦", Toast.LENGTH_LONG).show();
            }
            if (msg.what == 1004) {

                Intent intent = new Intent();
                intent.setAction("sign");
                startActivity(intent);
                return;
            }
            if (msg.what == 1005) {
                isdialogplayer = true;
                if (CurrentPlay != null) {
                    CurrentPlay.Playstop();
                }
                if (PrevPlay != null) {
                    PrevPlay.Playstop();
                }
                alertDialog.show();
                Log.i("IMG", "----------------------------");
                Log.i("IMG", currentdata.imgurl.get());
                Log.i("IMG", "----------------------------");
                DialogPlayer.setImgUrl(currentdata.imgurl.get());
                String uuu = (String) msg.obj;
                String param = null;
                try {
                    param = uuu+"?token="+ URLEncoder.encode(attribute.getToken(),"utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                Log.i("SSADADS",param);
                DialogPlayer.setPlayurl(param);
                DialogPlayer.loadVideo();
                if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) {
                    View view = FBB.recycler.getRootView();
                    view.setSystemUiVisibility(View.GONE);
                } else if (Build.VERSION.SDK_INT >= 19) {
                    View view = FBB.recycler.getRootView();
                    int UIOP = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
                    view.setSystemUiVisibility(UIOP);
                }

            }

            if (msg.what == 1006) {
                boolean bol = (boolean) msg.obj;
                if (bol) {
                    Toast.makeText(getContext(), "评价成功,审核后显示", Toast.LENGTH_SHORT).show();
                    editText.setText(null);
                } else {
                    Toast.makeText(getContext(), "评价失败。", Toast.LENGTH_SHORT).show();
                }
                return;
            }

            if (msg.what == 1007) {
                boolean abb = (boolean) msg.obj;
                if (abb) {
                    followView.setVisibility(View.GONE);
                } else {
                    followView.setVisibility(View.VISIBLE);
                }
            }
            if (msg.what == 1008) {
                boolean bool = (boolean) msg.obj;
                if (bool) {
                    if (Cview != null) {
                        Cview.findViewById(R.id.follow).setVisibility(View.GONE);
                    }
                } else {
                    if (Cview != null) {
                        Cview.findViewById(R.id.follow).setVisibility(View.VISIBLE);
                    }

                }
            }
        }
    };
}